<template>
	<view>
		<!-- 顶部导航栏 -->
		<view class="header">
			<x-status-bar></x-status-bar>
			<view class="flex-center-between header-navbar">
				<x-back-btn></x-back-btn>
				<view class="u-f-40 common-title">{{ lang_extension.extensionService }}</view>
				<view class="u-f-28 u-lh-40 font-medio" @click="jumpUrl(`/pages/shop/extension/save/save`)">{{ lang_extension.add }}</view>
			</view>
			
			<!-- 分割线 -->
			<u-gap height="1" bgColor="rgba(0, 0, 0, 0.07)"></u-gap>
		</view>
		
		<!-- 列表 -->
		<view>
			<mescroll-body height="calc(100vh - 100rpx - var(--status-bar-height))" ref="mescrollRef" @init="mescrollInit" @down="downCallback" @up="upCallback">
				<view>
					<view style="padding: 0 40rpx;">
						<view
						v-for="(item, index) in dataList"
						:key="index"
						class="u-p-t-34 u-p-b-30 flex-center-between"
						style="border-bottom: 2rpx solid rgba(151,151,151,.16);"
						@click="jumpUrl(`/pages/shop/extension/detail/detail?recordId=${ item.id }`)">
							<view class="flex-between flex-column">
								<view class="u-f-32 u-lh-44 font-medio">{{ lang_extension.shopActiveHot }}</view>
								<view class="u-m-t-10 flex-center color-grew u-f-28 u-lh-40">{{ lang_extension.buyTime }}{{ item.startTime && dayjs(item.startTime).format('YYYY-MM-DD HH:mm') || '' }}</view>
							</view>
							
							<view class="flex-center">
								<view class="u-lh-38 flex-baseline font-bold color-red">
									<view class="u-f-32">{{ lang_unit.money }}</view>
									<view class="u-f-58">{{ item.payAmount }}</view>
								</view>
								<u-icon name="right" custom-prefix="u" size="28" color="#999999"></u-icon>
							</view>
						</view>
					</view>
					<!-- 留空 -->
					<view style="height: 200rpx;"></view>
				</view>
			</mescroll-body>
		</view>
	</view>
</template>

<script>
	import { merchantPromoteRecordPage } from '@/api/merchant/merchant.js'
	import MescrollMixin from "@/components/mescroll-uni/mescroll-mixins.js";

	export default {
		mixins: [MescrollMixin], // 使用mixin
		data() {
			return {
				dataList: []
			}
		},
		onShow() {
			this.downCallback()
		},
		methods: {
			/*上拉加载的回调: 其中page.num:当前页 从1开始, page.size:每页数据条数,默认10 */
			upCallback(page) {
				let node = this.$refs['mescrollRef']
				merchantPromoteRecordPage({
					pageNumber: page.num,
					pageSize: page.size
				}).then(res => {
					node && node.mescroll.endSuccess(res.list.length);
					if (page.num == 1) this.dataList = []; //如果是第一页需手动制空列表
					this.dataList = this.dataList.concat(res.list); //追加新数据
				}).catch(() => {
					node && node.mescroll.endErr();
				})
			},
			downCallback() {
				let node = this.$refs['mescrollRef']
				node && node.mescroll.resetUpScroll()
			},
		}
	}
</script>

<style scoped lang="scss">

</style>
